package labox.innovation.gameserver.model;

import labox.innovation.config.Config;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.timer.Timer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author ljsh
 * @date 2010-4-12
 * @version 1.0
 * @description 关于组队成员离线的内存结构
 */
public class PartyMemberExDropped {
	private static final Logger _log = LoggerFactory.getLogger(PartyMemberExDropped.class);
	/**
	 * 玩家对应的队伍
	 */
	private L2Party party;
	/**
	 * 离线时间
	 */
	private long dropTime;
	/**
	 * 
	 */
	private long character;

	public Timer timer;

	public PartyMemberExDropped(L2Party party,  FuzePcInstance character) {
		if (party == null) {
			return;
		}
		this.party = party;
		dropTime = System.currentTimeMillis();
		this.character = character.getObjectId();
		timer = new Timer(Config.LOGOUTCHECKTIME, false, new Runnable() {
			@Override
			public void run() {
				if (_log.isDebugEnabled())
					_log.debug("执行玩家在组队状态下的离线任务 ： 队伍_" + PartyMemberExDropped.this.getParty() + " 玩家_" + PartyMemberExDropped.this.getCharacter());
				L2Party p = PartyMemberExDropped.this.getParty();
				if (p != null) {
					p.removePartyMember(PartyMemberExDropped.this.getParty().getPlayerById(PartyMemberExDropped.this.getCharacter()));
				}
				L2PartyManager.getInstance().getAllOfflinePlayer().remove(PartyMemberExDropped.this.getCharacter());

			}
		});
		if(timer!=null){
			timer.start();
		}
	}

	public long getDropTime() {
		return dropTime;
	}

	public L2Party getParty() {
		return party;
	}

	public void setParty(L2Party party) {
		this.party = party;
	}

	public long getCharacter() {
		return character;
	}

	public void setCharacterId(long character) {
		this.character = character;
	}

	public void cancel() {
		if(timer!=null)
		timer.cancel();
	}
}
